<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';
require_once './include/advisory_db.php';
//print_r($_SESSION);
$smarty->compile_check = true;

$rs['re_id'] = $_GET['id'];

$smarty->display('header.tpl');
//'option'=>$jobcategory

$_GET[view] == "op" && $rs = $DB->fetch_one_array("SELECT * FROM pa_resume WHERE `re_id` =" . $rs[re_id] . " AND ( `re_private` <> 1 OR ( `re_private` = 1  AND `re_uid` = '" . $_SESSION['uid'] . "')) ");


//check friends
$noFriends = 0;
if ($rs['re_usertype'] == 'recruiter' && $_SESSION['status'] <> 'Premium') {
    if (!areFriends($_SESSION['uid'], $rs['re_uid']) && $_SESSION['uid'] != $rs['re_uid']) {
        $noFriends = 1;
    }
}

if ($rs[re_id] == '' || $_GET[view] != "op" || $noFriends == 1) {
    $err = "Invalid ID! You have no permisson to view this page.";
    $smarty->assign("err", $err);
    $smarty->display("left.tpl");
    $smarty->display("error.tpl");
    $smarty->display("right.tpl");
    $smarty->display('footer.tpl');
    exit;
}


if ($rs[re_private] == 1 && $rs['re_uid'] != $_SESSION['uid']) {
    $err = "You cannot access this page!";
    $smarty->assign("err", $err);
    $smarty->display("left.tpl");
    $smarty->display("error.tpl");
    $smarty->display("right.tpl");
    $smarty->display('footer.tpl');
    exit;
}

if ($rs[re_aliasname] != '')
    $aliasname = "   (" . $rs[re_aliasname] . ")";
if ($rs[re_usertype] == 'recruiter') {
    $smarty->assign("name", $rs[re_nickname]);
} else {
    $smarty->assign("name", $rs[re_fname] . " " . $rs[re_lname] . $aliasname);
}
$smarty->assign("imgurl", $rs[re_upload]);

if ($rs[re_aliasname] != '') {
    $fid = $rs[re_fid];
    $rid = $rs[re_fid];
} else {
    $fid = $rs[re_id];
    $rid = $rs[re_id];
}

if (!file_exists("./uploadfiles/resumes/$rs[re_upload]") || $rs[re_upload] == '') {
    $rs[re_upload] = "noimages.jpg";
}

// user resume view
if(($_SESSION['status'] == 'Standard' || $_SESSION['status'] == 'Trial' )&& $_SESSION['uid'] <> $rs['re_uid']) {
	$accessid = $_GET['id'];
	$userrecords = $DB->fetch_one_array("SELECT * FROM pa_userrecords WHERE userid = '".$_SESSION[uid]."' AND usertype='recruiter' AND type='0'");
	$urcid = $userrecords['id'];

	if ($userrecords['date'] == date('Y-m')) {
		$urcd = $DB->fetch_one_array("SELECT urcid FROM pa_userrecords_data WHERE urcid = '".$urcid."' AND accessid = '".$accessid."'");
		if (!$urcd['urcid']) {
			if($_SESSION['status'] == 'Standard'){$sqlKey = 'recruiter_resume_view';}
			if($_SESSION['status'] == 'Trial'){$sqlKey = 'starter_resume_view';}
				
			$records_setting = $DB->fetch_one_array("SELECT `value` FROM pa_settings WHERE `key` = '".$sqlKey."' ");
			if($userrecords['amount'] >= $records_setting['value']) {
				$smarty->assign('jquery', 1);
				$smarty->assign('fancybox', 1);
				$smarty->assign('user_over', 1);
				accessblock(array("Trial","Standard","Pending"));
				exit;

			}else{
				$DB->query("INSERT INTO pa_userrecords_data (urcid, accessid) VALUES ('".$urcid."', '".$accessid."')");
				$DB->query("UPDATE pa_userrecords SET amount=amount+1 WHERE userid = '".$_SESSION[uid]."' AND usertype='recruiter' AND type='0'");
			}
		}
	} else {
		if($userrecords['date']) {
			$DB->query("DELETE FROM pa_userrecords_data WHERE urcid = '".$urcid."'");
			$DB->query("UPDATE pa_userrecords SET 
			amount = '1',
			date = '".date('Y-m')."' 
			WHERE userid = '".$_SESSION[uid]."' AND usertype='recruiter' AND type='0'");
			$DB->query("INSERT INTO pa_userrecords_data (urcid, accessid) VALUES ('".$urcid."', '".$accessid."')");
		}else{
			$DB->query("INSERT INTO pa_userrecords SET 
			userid = '".$_SESSION[uid]."',
			amount = '1',
			date = '".date('Y-m')."',
			usertype='recruiter',
			type='0'");
			$urcid = $DB->insert_id();
			$DB->query("INSERT INTO pa_userrecords_data (urcid, accessid) VALUES ('".$urcid."', '".$accessid."')");
		}
	}

}

ob_clean();
ob_start();
$view = 1;
//$cpforms->getimage(array('view'=>"$view"));
//echo '<div style="position:absolute;margin:30px 0 0 400px;padding:0"><img src="uploadfiles/resumes/'.$rs[re_upload].'" width="120" height="120" style="border:1px solid orange"></div>';
$cpforms->formheader(array('title' => 'Candidate Record', 'name' => 'article', 'enctype' => 'multipart/form-data'));
$cpforms->makehidden(array('name' => 'action', 'value' => 'resume_doupdate'));
$cpforms->makehidden(array('name' => 'editid', 'value' => $_GET[id]));
if ($rs[re_updtime] == 0) {
    $rs[re_updtime] = $rs[re_regtime];
}
$jobSearchStatus[$rs[re_jobsearchstatus]] = ($rs[re_jobsearchstatus] == 0) ? "N/A" : $jobSearchStatus[$rs[re_jobsearchstatus]];
echo
'<tr><td colspan="2" class="tbhead" style="margin:0;padding:0">
			<table width="100%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#FFFFFF">
			<tr class="firstalt" nowrap><td width="40%" >Create Date:</td><td  width="30%" >' . @date("m/d/Y", $rs[re_regtime]) . '</td><td rowspan="4" width="30%" ><img src="uploadfiles/resumes/' . $rs[re_upload] . '" width="120" height="120" style="border:1px solid orange"></td></tr>
			<tr class="firstalt" nowrap><td >Last Update:</td><td  >' . @date("m/d/Y", $rs[re_updtime]) . '</td></tr>
			<tr class="firstalt" nowrap><td >User Type:</td><td >' . $rs[re_usertype] . '</td></tr>
			<tr class="firstalt" nowrap><td >Job Search Status:</td><td  >' . $jobSearchStatus[$rs[re_jobsearchstatus]] . '</td></tr>
            </table>
            </td>
            </tr>';
$cpforms->longline(array('title' => "Contact Information"));

if ($rs[re_uid] == $_SESSION[uid] || $rs[re_usertype] <> 'recruiter') {
    $cpforms->gethightext(array('text' => "First Name", 'name' => "re_fname", 'value' => "$rs[re_fname]", 'view' => "$view"));
    $cpforms->gethightext(array('text' => "Last Name", 'name' => "re_lname", 'value' => "$rs[re_lname]", 'view' => "$view"));
    $cpforms->gethightext(array('text' => "Nick Name", 'name' => "re_nickname", 'value' => "$rs[re_nickname]", 'view' => "$view", 'icon' => "'Type a nick name for this candidate. When you submit this candidate profile to a job, this Nick Name will be displayed.', WIDTH, 200, SHADOW, true"));

    $cpforms->gethightext(array('text' => "Contact Email", 'name' => "re_email", 'value' => "$rs[re_email]", 'view' => "$view", 'email' => 1));
    $cpforms->gethightext(array('text' => "Street Address 1", 'name' => "re_address1", 'value' => "$rs[re_address1]", 'view' => "$view"));
    $cpforms->gethightext(array('text' => "Street Address 2", 'name' => "re_address2", 'value' => "$rs[re_address2]", 'view' => "$view"));
    $cpforms->gethightext(array('text' => "Location - City", 'name' => "re_locity", 'value' => "$rs[re_locity]", 'view' => "$view"));
    $cpforms->makeselect(array('text' => "Location - State", 'name' => "re_lostate", 'option' => $state, 'selected' => "$rs[re_lostate]", 'view' => "$view", 'viewfunction' => 'state'));
    $cpforms->makeselect(array('text' => "Location - Country", 'name' => "re_locountry", 'option' => $country, 'selected' => "$rs[re_locountry]", 'view' => "$view", 'viewfunction' => 'country'));
    $cpforms->gethightext(array('text' => "Primary Phone", 'name' => "re_phone1", 'value' => "$rs[re_phone1]", 'view' => "$view"));
    //$cpforms->gethightext(array ('text' => "Recruiter Contact",'name' => "re_phone2",'value' => "$rs[re_phone2]",'view' => "$view"));
}

if ($rs[re_usertype] == 'recruiter') {
    $cpforms->maketextarea(array('text' => "Recruiter Contact.", 'name' => "re_phone2", 'value' => "$rs[re_phone2]", 'view' => "$view", 'email' => 1, 'txtextra' => '<a href="recdetail.php?id=' . $rs['re_uid'] . '"><img src="images/0441.png"  border="0" align="absmiddle"></a>'));
}
if ($rs[re_uid] == $_SESSION[uid] && $rs[re_usertype] == 'recruiter') {
    $cpforms->makefck(array('text' => "Comments", 'name' => "re_rccomment", 'id' => "re_rccomment", 'only' => 0, 'value' => $rs[re_rccomment], 'view' => "$view", 'icon' => "'Add notes or comments about this candidate here.', WIDTH, 200, SHADOW, true"));
}


$cpforms->longline(array('title' => "Desired Job Detail"));
$cpforms->makeselect(array('text' => "Desired Job Type", 'name' => "re_jobtype", 'option' => $jobtype, 'selected' => "$rs[re_jobtype]", 'view' => "$view"));
$cpforms->makeselect(array('text' => "Desired Job Industry", 'name' => "re_jobindustry", 'option' => $jobcategory, 'selected' => "$rs[re_jobindustry]", 'view' => "$view"));
$cpforms->gethightext(array('text' => "Desired Job Title", 'name' => "re_jobtitle", 'value' => "<font color='blue'><b>$rs[re_jobtitle]</b></font>", 'view' => "$view"));
$cpforms->gethightext(array('text' => "Current Base Pay", 'name' => "re_currentpay", 'value' => "$rs[re_currentpay]", 'view' => "$view", 'icon' => "'Indicate current annual base salary', WIDTH, 200, SHADOW, true", "prev" => "$"));
$cpforms->gethightext(array('text' => "Desired Base Pay", 'name' => "re_desiredpay", 'value' => "$rs[re_desiredpay]", 'view' => "$view", 'icon' => "'Indicate desired annual base salary', WIDTH, 200, SHADOW, true", "prev" => "$"));
$cpforms->maketextarea(array('text' => "Other Compensation/Benefits", 'name' => "re_benefits", 'value' => stripslashes($rs[re_benefits]), 'view' => "$view", 'icon' => "'Indicate other preferred compensation or benefits such as sign-on bonus or stock grants.  ', WIDTH, 200, SHADOW, true"));
$cpforms->longline(array('title' => "Qualifications"));
$cpforms->maketextarea(array('text' => "Schools Attended", 'name' => "re_schoolattend", 'value' => stripslashes($rs[re_schoolattend]), 'view' => "$view"));

$cpforms->makeselect(array('text' => "Highest Education Level", 'name' => "re_edulevel", 'option' => $education, 'selected' => "$rs[re_edulevel]", 'view' => "$view", 'viewfunction' => 'education', 'icon' => "' Indicate the highest level of education achieved here.', WIDTH, 200, SHADOW, true"));
$cpforms->gethightext(array('text' => "Professional Licenses/Certification", 'name' => "re_proflicense", 'value' => "$rs[re_proflicense]", 'view' => "$view", 'icon' => "'List all professional licenses or certifications obtained here.', WIDTH, 200, SHADOW, true"));
$cpforms->makeselect(array('text' => "Years of Work Experience", 'name' => "re_yearexp", 'option' => $yearexp2, 'selected' => "$rs[re_yearexp]", 'view' => "$view", 'viewfunction' => 'yearexp'));
$cpforms->makeselect(array('text' => "Years of People Mgmt Experience", 'name' => "re_mgmt", 'option' => $yearexp2, 'selected' => "$rs[re_mgmt]", 'view' => "$view", 'viewfunction' => 'yearexp'));
$cpforms->makeselect(array('text' => "Years of Profit & Loss Responsibility", 'name' => "re_profit", 'option' => $yearexp2, 'selected' => "$rs[re_profit]", 'view' => "$view", 'viewfunction' => 'yearexp'));
$cpforms->gethightext(array('text' => "Spoken Language(s)", 'name' => "re_spoken", 'value' => "$rs[re_spoken]", 'view' => "$view"));
$cpforms->gethightext(array('text' => "Programming Language Knowledge", 'name' => "re_prolang", 'value' => "$rs[re_prolang]", 'view' => "$view"));
$cpforms->gethighradio(array('text' => "High-Tech Patent/IP owner or Co-owner?", 'name' => "re_ip", 'selected' => "$rs[re_ip]", 'view' => "$view"));
$cpforms->gethighradio(array('text' => "U.S.Government Security Clearance?", 'name' => "re_ussecurity", 'selected' => "$rs[re_ussecurity]", 'view' => "$view"));
//$cpforms->gethightext(array ('text' => "Indicate in which country the candidate is authorized to work.",'name' => "re_authorize",'value' => $rs[re_authorize],'view' => "$view",'icon'=>"'Indicate  job search status.  You may edit this later.', WIDTH, 200, SHADOW, true"));
$cpforms->maketextarea(array('text' => "Authorized to work in the following country", 'name' => "re_authorize", 'value' => "$rs[re_authorize]", 'view' => "$view", 'icon' => "' Indicate in which country the candidate is authorized to work.', WIDTH, 200, SHADOW, true"));
$cpforms->maketextarea2(array('text' => "Resume Detail", 'name' => "re_detail", 'value' => stripslashes($rs[re_detail]), 'view' => "$view", 'icon' => "' Please include details of all relevant work experience, education and training here.  You can type-in your content or cut and paste them.  Please DO NOT include your name or contact information here.', WIDTH, 200, SHADOW, true"));
if ($_SESSION[usertype] == "candidate" || $rs[re_usertype] == "candidate") {
    $cpforms->longline(array('title' => "More About Me��"));
    $cpforms->gethightext(array('text' => "My family/friends would describe me as��", 'name' => "re_describeme", 'value' => "$rs[re_describeme]", 'view' => "$view", 'icon' => "'Please describe in 250 characters or less.  You may edit this later.', WIDTH, 200, SHADOW, true"));
    $cpforms->gethightext(array('text' => "My favoriate book is��because��", 'name' => "re_favoriatebook", 'value' => "$rs[re_favoriatebook]", 'view' => "$view", 'icon' => "'Please describe in 250 characters or less.  You may edit this later.', WIDTH, 200, SHADOW, true"));
    $cpforms->gethightext(array('text' => "My highest achievement is��", 'name' => "re_highachieve", 'value' => "$rs[re_highachieve]", 'view' => "$view", 'icon' => "'Please describe in 250 characters or less.  You may edit this later.', WIDTH, 200, SHADOW, true"));
    $cpforms->gethightext(array('text' => "In 3 to 5 years, I plan to��", 'name' => "re_iplan", 'value' => "$rs[re_iplan]", 'view' => "$view", 'icon' => "'Please describe in 250 characters or less.  You may edit this later.', WIDTH, 200, SHADOW, true"));
    $cpforms->gethightext(array('text' => "When I'm not working I like to��", 'name' => "re_iliketo", 'value' => "$rs[re_iliketo]", 'view' => "$view", 'icon' => "'Please describe in 250 characters or less.  You may edit this later.', WIDTH, 200, SHADOW, true"));
    $cpforms->gethightext(array('text' => "My Personal Website or Blog Link ", 'name' => "re_personalweb", 'value' => "$rs[re_personalweb]", 'view' => "$view", 'icon' => "'etc. http://www.enetrecruiter.com', WIDTH, 200, SHADOW, true"));
    $cpforms->maketextarea(array('text' => "Comments", 'name' => "re_comments", 'value' => stripslashes($rs[re_comments]), 'view' => "$view", 'icon' => "'You may include additional comments here for view by recruiters.', WIDTH, 200, SHADOW, true"));
    //$cpforms->makefile(array ('text' => "Picture (Upload an image size 100��100)",'name' => "uploadfile",'value'=>"$re_upload",'url'  => "uploadfiles/resumes/",'view' => "$view"));
}
if ($_SESSION[usertype] == "recruiter" && $rs[re_uid] == $_SESSION[uid]) {
    $cpforms->longline(array('title' => "Work Status, Employment and Professional References"));
    $cpforms->maketextarea(array('text' => "Three Previous Employers", 'name' => "re_prvemployer", 'value' => "$rs[re_prvemployer]", 'view' => "$view", 'icon' => "'Please list 3 previous employers.', WIDTH, 200, SHADOW, true"));
    $cpforms->gethighradio(array('text' => "Previous Employment Status Checked?", 'name' => "re_prvempstatus", 'selected' => "$rs[re_prvempstatus]", 'view' => "$view", 'icon' => "'You are not required to perform employment status checking prior to submitting the applicant.  But it may improve your applicant\'s chances of being considered before other applicants.  Be ready to provide the necessary information if requested by the employer.', WIDTH, 200, SHADOW, true"));
    $cpforms->gethighradio(array('text' => "Three Professional References Available?", 'name' => "re_professavilable", 'selected' => "$rs[re_professavilable]", 'view' => "$view", 'icon' => "'Does the applicant have a minimum of 3 references available to speak of his/her past work performance?  This is not required but may improve your applicant\'s chances of being considered before others.  Be ready to provide the necessary information if asked by the employer.', WIDTH, 200, SHADOW, true"));
    //$cpforms->gethighradio(array ('text' => "Will the applicant require work sponsorship for this job?",'name' => "re_sponsorship",'selected' => "$rs[re_sponsorship]",'view' => "$view"));
}

if ($_SESSION[uid] == $rs[re_uid] && $rs[re_usertype] == "recruiter" && $_SESSION['status'] == "Premium")
    $alias = "alias";
if ($_SESSION[uid] == $rs[re_uid])
    $editButton = 1;
if ($rs[re_usertype] == "recruiter" && $_SESSION[uid] <> $rs[re_uid])
    $sendmessage = 1;
$cpforms->noformfooter($alias, $fid, $_GET[action], $_GET[alias], $editButton, $sendmessage);
$reg_data = ob_get_contents();
ob_end_clean();

$smarty->assign('title', $title);

if ($err != '') {
    $smarty->assign("err", $err);
}

if ( $_GET['alias'] != 1 && $_SESSION[uid] == $rs[re_uid] && $rs[re_usertype] == "recruiter" && $_SESSION['status'] == "Premium") {
    $smarty->assign("aliasbutton", '<input type="button" value="Create Alias" onclick="location.href=\'postresumealias.php?id=' . $rid . '\'" class="button-secondary"> <a href="###" onmouseover="Tip(\'You may create up to 99  alias copies of this candidate record.\', WIDTH, 200, SHADOW, true)"><img src="images/icn_question.jpg" border="0" align="absmiddle" /></a>');
} elseif ($_SESSION[uid] == $rs[re_uid] && $rs[re_usertype] == "recruiter") {
    $smarty->assign("editbutton", '<input type="button" value=" Edit " onclick="location.href=\'postresume.php?action=edit&id=' . $rid . '\'" class="button-secondary">');
    $smarty->assign("publicviewbutton", '<input type="button" value=" Public View " onclick="location.href=\'publicviewresume.php?view=op&id=' . $_GET['id'] . '\'" class="button-secondary">');
}
$rs['re_mgmt'] = ($rs['re_mgmt'] != 0) ? $yearexp2[$rs['re_mgmt']] : "N/A";
$rs['re_profit'] = ($rs['re_profit'] != 0) ? $yearexp2[$rs['re_profit']] : "N/A";
$rs['re_edulevel'] = ($rs['re_edulevel'] != 0) ? $education[$rs['re_edulevel']] : "N/A";
$rs['re_jobindustry'] = ($rs['re_jobindustry'] != '0') ? $jobcategory[$rs['re_jobindustry']] : "N/A";
$rs['re_jobsearchstatus'] = $jobSearchStatus[$rs[re_jobsearchstatus]];
$rs['re_regtime'] = @date("m/d/Y", $rs[re_regtime]);
$rs['re_lostate'] = ($rs['re_lostate'] != 0) ? $state[$rs['re_lostate']] : "N/A";
$rs['re_locountry'] = ($rs['re_locountry'] != 0) ? $country[$rs['re_locountry']] : "N/A";
$rs['re_jobtype'] = ($rs['re_jobtype'] != 0) ? $jobtype[$rs['re_jobtype']] : "N/A";

$smarty->assign("rs", $rs);
$smarty->assign("reg", $reg_data);
$smarty->display('allleft.tpl');
$smarty->display('resumeaction.tpl');


$smarty->display('allright.tpl');
$smarty->display('footer.tpl');